package cn.gmph.blog.admin.service.post.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import cn.gmph.blog.admin.service.post.dao.helper.PostsProvider;
import cn.gmph.blog.admin.service.post.entity.PostsDO;
import cn.gmph.blog.admin.web.dto.QueryDTO;;

public interface PostsDAO {


    @Results({ @Result(column = "ID", property = "id"), @Result(column = "post_author", property = "postAuthor"), @Result(column = "post_date", property = "postDate"),
               @Result(column = "post_date_gmt", property = "postDateGmt"), @Result(column = "post_content", property = "postContent"), @Result(column = "post_title", property = "postTitle"),
               @Result(column = "post_excerpt", property = "postExcerpt"), @Result(column = "post_status", property = "postStatus"), @Result(column = "comment_status", property = "commentStatus"),
               @Result(column = "ping_status", property = "pingStatus"), @Result(column = "post_password", property = "postPassword"), @Result(column = "post_name", property = "postName"),
               @Result(column = "to_ping", property = "toPing"), @Result(column = "post_modified", property = "postModified"), @Result(column = "post_modified_gmt", property = "postModifiedGmt"),
               @Result(column = "post_content_filtered", property = "postContentFiltered"), @Result(column = "post_parent", property = "postParent"),
               @Result(column = "menu_order", property = "menuOrder"), @Result(column = "post_type", property = "postType"), @Result(column = "post_mime_type", property = "postMimeType"),
               @Result(column = "comment_count", property = "commentCount") })
    @Select("SELECT * FROM wp_posts WHERE ID in (${ids})")

    public List<PostsDO> selectByIds(@Param("ids") String ids);

    @Results({ @Result(column = "ID", property = "id"), @Result(column = "post_author", property = "postAuthor"), @Result(column = "post_date", property = "postDate"),
               @Result(column = "post_date_gmt", property = "postDateGmt"), @Result(column = "post_content", property = "postContent"), @Result(column = "post_title", property = "postTitle"),
               @Result(column = "post_excerpt", property = "postExcerpt"), @Result(column = "post_status", property = "postStatus"), @Result(column = "comment_status", property = "commentStatus"),
               @Result(column = "ping_status", property = "pingStatus"), @Result(column = "post_password", property = "postPassword"), @Result(column = "post_name", property = "postName"),
               @Result(column = "to_ping", property = "toPing"), @Result(column = "post_modified", property = "postModified"), @Result(column = "post_modified_gmt", property = "postModifiedGmt"),
               @Result(column = "post_content_filtered", property = "postContentFiltered"), @Result(column = "post_parent", property = "postParent"),
               @Result(column = "menu_order", property = "menuOrder"), @Result(column = "post_type", property = "postType"), @Result(column = "post_mime_type", property = "postMimeType"),
               @Result(column = "comment_count", property = "commentCount") })
    @Select("SELECT * FROM wp_posts WHERE ID = #{dto.id}")
    public PostsDO selectByPrimaryKey(QueryDTO dto);

    @Results({ @Result(column = "ID", property = "id"), @Result(column = "post_author", property = "postAuthor"), @Result(column = "post_date", property = "postDate"),
               @Result(column = "post_date_gmt", property = "postDateGmt"), @Result(column = "post_content", property = "postContent"), @Result(column = "post_title", property = "postTitle"),
               @Result(column = "post_excerpt", property = "postExcerpt"), @Result(column = "post_status", property = "postStatus"), @Result(column = "comment_status", property = "commentStatus"),
               @Result(column = "ping_status", property = "pingStatus"), @Result(column = "post_password", property = "postPassword"), @Result(column = "post_name", property = "postName"),
               @Result(column = "to_ping", property = "toPing"), @Result(column = "post_modified", property = "postModified"), @Result(column = "post_modified_gmt", property = "postModifiedGmt"),
               @Result(column = "post_content_filtered", property = "postContentFiltered"), @Result(column = "post_parent", property = "postParent"),
               @Result(column = "menu_order", property = "menuOrder"), @Result(column = "post_type", property = "postType"), @Result(column = "post_mime_type", property = "postMimeType"),
               @Result(column = "comment_count", property = "commentCount") })
    @Select("SELECT * FROM wp_posts WHERE ID = #{id}")
    public PostsDO getById(@Param("id") int id);

    @Insert("INSERT into wp_posts(ID,post_author,post_date,post_date_gmt,post_content,post_title,post_excerpt,post_status,comment_status,ping_status,post_password,post_name,to_ping,pinged,post_modified,post_modified_gmt,post_content_filtered,post_parent,guid,menu_order,post_type,post_mime_type,comment_count) VALUES (#{id},#{postAuthor},#{postDate},#{postDateGmt},#{postContent},#{postTitle},#{postExcerpt},#{postStatus},#{commentStatus},#{pingStatus},#{postPassword},#{postName},#{toPing},#{pinged},#{postModified},#{postModifiedGmt},#{postContentFiltered},#{postParent},#{guid},#{menuOrder},#{postType},#{postMimeType},#{commentCount})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    public void insert(PostsDO posts);

    @Delete("DELETE FROM wp_posts WHERE id = #{id}")
    public int deleteById(@Param("id") Long id);

    @UpdateProvider(type = PostsProvider.class, method = "update")
    public int update(@Param("posts") PostsDO posts);

    @Results({ @Result(column = "ID", property = "id"), @Result(column = "post_author", property = "postAuthor"), @Result(column = "post_date", property = "postDate"),
               @Result(column = "post_date_gmt", property = "postDateGmt"), @Result(column = "post_content", property = "postContent"), @Result(column = "post_title", property = "postTitle"),
               @Result(column = "post_excerpt", property = "postExcerpt"), @Result(column = "post_status", property = "postStatus"), @Result(column = "comment_status", property = "commentStatus"),
               @Result(column = "ping_status", property = "pingStatus"), @Result(column = "post_password", property = "postPassword"), @Result(column = "post_name", property = "postName"),
               @Result(column = "to_ping", property = "toPing"), @Result(column = "post_modified", property = "postModified"), @Result(column = "post_modified_gmt", property = "postModifiedGmt"),
               @Result(column = "post_content_filtered", property = "postContentFiltered"), @Result(column = "post_parent", property = "postParent"),
               @Result(column = "menu_order", property = "menuOrder"), @Result(column = "post_type", property = "postType"), @Result(column = "post_mime_type", property = "postMimeType"),
               @Result(column = "comment_count", property = "commentCount") })
    @SelectProvider(type = PostsProvider.class, method = "pageList")
    public List<PostsDO> pageList(@Param("posts") PostsDO posts, @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);

    @SelectProvider(type = PostsProvider.class, method = "pageListCount")
    public Integer pageListCount(@Param("posts") PostsDO posts);

}